package com.heima.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.PageResult;
import com.heima.mapper.SkuClassMapper;
import com.heima.pojo.SkuClass;
import com.heima.pojo.vo.SkuClassVo;
import com.heima.service.ISkuClassService;
import org.springframework.stereotype.Service;

@Service
public class SkuClassServiceImpl extends ServiceImpl<SkuClassMapper, SkuClass> implements ISkuClassService {

    /**
     * 查询分类
     * @param className 类名称
     * @return
     */
    @Override
    public PageResult<SkuClassVo> search(PageResult<SkuClassVo> pageResult, String className) {
        LambdaQueryWrapper<SkuClass> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(className), SkuClass::getClassName, className);
        Page<SkuClass> page = this.page(new Page<>(pageResult.getPageIndex(), pageResult.getPageSize()), wrapper);
        return pageResult.of(page, SkuClassVo.class);
    }

}
